Skip to content

Conversation

@nisedo
Copy link
Contributor

@nisedo nisedo commented Jan 25, 2026

Context / Bug

slither-lsp imports LanguageServer from pygls.server.

In pygls>=2.0, LanguageServer was moved to pygls.lsp.server, so the import fails and the LSP crashes on startup with:

ImportError: cannot import name 'LanguageServer' from 'pygls.server'

Impact

Any environment that resolves pygls>=2 (e.g., uv tool installs) fails to start slither-lsp, causing the VSCode extension to repeatedly restart the server and never initialize.

Fix

Add a backward‑compatible import shim that tries the old path first and falls back to the new path:

try:
from pygls.server import LanguageServer
except ImportError:
from pygls.lsp.server import LanguageServer

Applied consistently in:

- slither_lsp/app/slither_server.py
- slither_lsp/app/logging/lsp_handler.py
- slither_lsp/app/request_handlers/analysis/get_detector_list.py
- slither_lsp/app/request_handlers/analysis/get_version.py
- slither_lsp/app/request_handlers/compilation/get_command_line_args.py

### Why this approach

- Preserves compatibility with pygls<2 without breaking existing environments.
- Unblocks pygls>=2 without pinning dependencies.
- Minimal, lowrisk change: only import paths, no behavior changes.

### Testing

Manual: verified that slither-lsp starts with pygls>=2 after the change (previously crashed).

- Update pygls dependency to >=2.0.0
- Update imports from pygls.server to pygls.lsp.server
- Update method calls to use v2 params-based API:
  - show_message() -> window_show_message(ShowMessageParams)
  - show_message_log() -> window_log_message(LogMessageParams)
  - publish_diagnostics() -> text_document_publish_diagnostics(PublishDiagnosticsParams)
- Update tests for new API

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@dguido dguido force-pushed the fix/pygls-2-compat branch from 9c33bad to 97eb4ae Compare January 26, 2026 18:44
@dguido dguido merged commit 41156fb into main Jan 26, 2026
7 checks passed
@dguido dguido deleted the fix/pygls-2-compat branch January 26, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants